package JDBC;

import java.sql.*;

public class DBUtil {
	private final static String DRIVER_CLASS = "oracle.jdbc.driver.OracleDriver";
	private final static String URL = "jdbc:oracle:thin:@localhost:1521:XE";
	private final static String USERNAME = "system";
	private final static String PASSWORD = "password";
	static {
		try {
			Class.forName(DRIVER_CLASS);
		} catch (Exception e) {
			System.out.println("Driver class not Found");
			e.printStackTrace();
		}
	}

	public static Connection getConnection() {
		Connection con = null;
		try {
			con = DriverManager.getConnection(URL, USERNAME, PASSWORD);
		} catch (SQLException e) {
			System.out.println("Error in Database Operation");
			e.printStackTrace();
		}
		return con;
	}

	public static void close(ResultSet rs, Statement st, Connection con) {
		try {
			if (rs != null)
				rs.close();
			if (st != null)
				st.close();
			if (con != null)
				con.close();
		} catch (SQLException e) {
			System.out.println("Error in Closing the Resources");
			e.printStackTrace();
		}
	}
}